//
//  DFMainViewController.swift
//  FlyBlog
//
//  Created by FEI on 16/4/8.
//  Copyright © 2016年 FEI. All rights reserved.
//

import UIKit

class DFMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let mainButton = DFMainTabBar()

        mainButton.composeClosure = { () -> Void in
            self.presentViewController(UINavigationController(rootViewController: DFComposeViewController()), animated: true, completion: nil)
        }

        setValue(mainButton, forKey: "tabBar")

        tabBar.tintColor = UIColor.orangeColor()

        setupChildViewControllers()

    }

    private func setupChildViewControllers (){

        setupChildViewController(DFHomeViewController(), imageName: "tabbar_home", title: "首页")

        setupChildViewController(DFMessageViewController(), imageName: "tabbar_message_center", title: "消息")

        setupChildViewController(DFDiscoverViewController(), imageName: "tabbar_discover", title: "发现")

        setupChildViewController(DFProfileViewController(), imageName: "tabbar_profile", title: "我")

//        let homeVC = DFHomeViewController()
//        homeVC.title = "首页"
//        homeVC.tabBarItem.image = UIImage(named: "tabbar_home")
//        vc.addChildViewController(UINavigationController(rootViewController: homeVC))
//
//        let messageVC = DFMessageViewController()
//        messageVC.title = "消息"
//        messageVC.tabBarItem.image = UIImage(named: "tabbar_message_center")
//        vc.addChildViewController(UINavigationController(rootViewController:messageVC))
//
//        let discoverVC = DFDiscoverViewController()
//        discoverVC.title = "发现"
//        discoverVC.tabBarItem.image = UIImage(named: "tabbar_discover")
//        vc.addChildViewController(UINavigationController(rootViewController:discoverVC))
//
//        let mineVC = DFProfileViewController()
//        mineVC.title = "我"
//        mineVC.tabBarItem.image = UIImage(named: "tabbar_profile")
//        vc.addChildViewController(UINavigationController(rootViewController:mineVC))

    }

    private func setupChildViewController(controller:UIViewController,imageName:String,title:String){

        controller.title = title

        controller.tabBarItem.image = UIImage(named: imageName)

//        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//
//        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)


        addChildViewController(UINavigationController(rootViewController: controller))

    }


}
